


/*
'===============================================================================
'  HNG.Portal.BL.TblMediaManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblMediaManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_CateMediaId="CateMediaId";
				
				public const String Field_CategoryName="CategoryName";
				
				public const String Field_NhomFileId="NhomFileId";
				
				public const String Field_TenNhomFile="TenNhomFile";
				
				public const String Field_DinhDang="DinhDang";
				
				public const String Field_TenMedia="TenMedia";
				
				public const String Field_Link="Link";
				
				public const String Field_Description="Description";
				
				public const String Field_ViTri="ViTri";
				
				public const String Field_ThuTu="ThuTu";
				
				public const String Field_Image="Image";
				
				public const String Field_Type="Type";
				
				public const String Field_NgayDang="NgayDang";
				
				public const String Field_TrangThai="TrangThai";
				
				public const String Field_LangId="LangId";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblMediaManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_CateMediaId,typeof(int));
			
						
			
			dt.Columns.Add(Field_CategoryName,typeof(string));
			
						
			
			dt.Columns.Add(Field_NhomFileId,typeof(int));
			
						
			
			dt.Columns.Add(Field_TenNhomFile,typeof(string));
			
						
			
			dt.Columns.Add(Field_DinhDang,typeof(string));
			
						
			
			dt.Columns.Add(Field_TenMedia,typeof(string));
			
						
			
			dt.Columns.Add(Field_Link,typeof(string));
			
						
			
			dt.Columns.Add(Field_Description,typeof(string));
			
						
			
			dt.Columns.Add(Field_ViTri,typeof(string));
			
						
			
			dt.Columns.Add(Field_ThuTu,typeof(int));
			
						
			
			dt.Columns.Add(Field_Image,typeof(string));
			
						
			
			dt.Columns.Add(Field_Type,typeof(string));
			
						
			
			dt.Columns.Add(Field_NgayDang,typeof(DateTime));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
						
			
			dt.Columns.Add(Field_LangId,typeof(string));
			
			            
            return dt;			
		}
			
		public TblMediaEntity Convert_Entity(TblMediaEntity _TblMediaEntity,TblMediaEntity _TblMediaEntity_XML)
		{	
			
				
			_TblMediaEntity.Id= _TblMediaEntity_XML.Id;
				
			_TblMediaEntity.CateMediaId= _TblMediaEntity_XML.CateMediaId;
				
			_TblMediaEntity.CategoryName= _TblMediaEntity_XML.CategoryName;
				
			_TblMediaEntity.NhomFileId= _TblMediaEntity_XML.NhomFileId;
				
			_TblMediaEntity.TenNhomFile= _TblMediaEntity_XML.TenNhomFile;
				
			_TblMediaEntity.DinhDang= _TblMediaEntity_XML.DinhDang;
				
			_TblMediaEntity.TenMedia= _TblMediaEntity_XML.TenMedia;
				
			_TblMediaEntity.Link= _TblMediaEntity_XML.Link;
				
			_TblMediaEntity.Description= _TblMediaEntity_XML.Description;
				
			_TblMediaEntity.ViTri= _TblMediaEntity_XML.ViTri;
				
			_TblMediaEntity.ThuTu= _TblMediaEntity_XML.ThuTu;
				
			_TblMediaEntity.Image= _TblMediaEntity_XML.Image;
				
			_TblMediaEntity.Type= _TblMediaEntity_XML.Type;
				
			_TblMediaEntity.NgayDang= _TblMediaEntity_XML.NgayDang;
				
			_TblMediaEntity.TrangThai= _TblMediaEntity_XML.TrangThai;
				
			_TblMediaEntity.LangId= _TblMediaEntity_XML.LangId;
				
			
			return _TblMediaEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblMediaEntity Insert(TblMediaEntity TblMediaEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblMediaEntity, true);
			}
			return TblMediaEntity;
		}

		
		public TblMediaEntity Insert(int Id, int CateMediaId, string CategoryName, int NhomFileId, string TenNhomFile, string DinhDang, string TenMedia, string Link, string Description, string ViTri, int ThuTu, string Image, string Type, DateTime NgayDang, bool TrangThai, string LangId)
		{
			TblMediaEntity _TblMediaEntity = new TblMediaEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblMediaEntity.Id = Id;
				_TblMediaEntity.CateMediaId = CateMediaId;
				_TblMediaEntity.CategoryName = CategoryName;
				_TblMediaEntity.NhomFileId = NhomFileId;
				_TblMediaEntity.TenNhomFile = TenNhomFile;
				_TblMediaEntity.DinhDang = DinhDang;
				_TblMediaEntity.TenMedia = TenMedia;
				_TblMediaEntity.Link = Link;
				_TblMediaEntity.Description = Description;
				_TblMediaEntity.ViTri = ViTri;
				_TblMediaEntity.ThuTu = ThuTu;
				_TblMediaEntity.Image = Image;
				_TblMediaEntity.Type = Type;
				_TblMediaEntity.NgayDang = NgayDang;
				_TblMediaEntity.TrangThai = TrangThai;
				_TblMediaEntity.LangId = LangId;
				adapter.SaveEntity(_TblMediaEntity, true);
			}
			return _TblMediaEntity;
		}

		public TblMediaEntity Insert(int CateMediaId, string CategoryName, int NhomFileId, string TenNhomFile, string DinhDang, string TenMedia, string Link, string Description, string ViTri, int ThuTu, string Image, string Type, DateTime NgayDang, bool TrangThai, string LangId)
		{
			TblMediaEntity _TblMediaEntity = new TblMediaEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblMediaEntity.CateMediaId = CateMediaId;
				_TblMediaEntity.CategoryName = CategoryName;
				_TblMediaEntity.NhomFileId = NhomFileId;
				_TblMediaEntity.TenNhomFile = TenNhomFile;
				_TblMediaEntity.DinhDang = DinhDang;
				_TblMediaEntity.TenMedia = TenMedia;
				_TblMediaEntity.Link = Link;
				_TblMediaEntity.Description = Description;
				_TblMediaEntity.ViTri = ViTri;
				_TblMediaEntity.ThuTu = ThuTu;
				_TblMediaEntity.Image = Image;
				_TblMediaEntity.Type = Type;
				_TblMediaEntity.NgayDang = NgayDang;
				_TblMediaEntity.TrangThai = TrangThai;
				_TblMediaEntity.LangId = LangId;
				adapter.SaveEntity(_TblMediaEntity, true);
			}
			return _TblMediaEntity;
		}

		public bool Update(TblMediaEntity _TblMediaEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblMediaFields.Id == _TblMediaEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblMediaEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblMediaEntity _TblMediaEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblMediaEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int CateMediaId, string CategoryName, int NhomFileId, string TenNhomFile, string DinhDang, string TenMedia, string Link, string Description, string ViTri, int ThuTu, string Image, string Type, DateTime NgayDang, bool TrangThai, string LangId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblMediaEntity _TblMediaEntity = new TblMediaEntity(Id);
				if (adapter.FetchEntity(_TblMediaEntity))
				{
				
					_TblMediaEntity.CateMediaId = CateMediaId;
					_TblMediaEntity.CategoryName = CategoryName;
					_TblMediaEntity.NhomFileId = NhomFileId;
					_TblMediaEntity.TenNhomFile = TenNhomFile;
					_TblMediaEntity.DinhDang = DinhDang;
					_TblMediaEntity.TenMedia = TenMedia;
					_TblMediaEntity.Link = Link;
					_TblMediaEntity.Description = Description;
					_TblMediaEntity.ViTri = ViTri;
					_TblMediaEntity.ThuTu = ThuTu;
					_TblMediaEntity.Image = Image;
					_TblMediaEntity.Type = Type;
					_TblMediaEntity.NgayDang = NgayDang;
					_TblMediaEntity.TrangThai = TrangThai;
					_TblMediaEntity.LangId = LangId;
					adapter.SaveEntity(_TblMediaEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblMediaEntity _TblMediaEntity = new TblMediaEntity(Id);
				if (adapter.FetchEntity(_TblMediaEntity))
				{
					adapter.DeleteEntity(_TblMediaEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblMediaEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCateMediaId(int CateMediaId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.CateMediaId == CateMediaId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCategoryName(string CategoryName)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.CategoryName == CategoryName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByNhomFileId(int NhomFileId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.NhomFileId == NhomFileId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTenNhomFile(string TenNhomFile)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TenNhomFile == TenNhomFile);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDinhDang(string DinhDang)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.DinhDang == DinhDang);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTenMedia(string TenMedia)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TenMedia == TenMedia);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLink(string Link)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDescription(string Description)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByViTri(string ViTri)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.ViTri == ViTri);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByThuTu(int ThuTu)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.ThuTu == ThuTu);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByImage(string Image)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByType(string Type)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByNgayDang(DateTime NgayDang)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.NgayDang == NgayDang);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLangId(string LangId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblMediaEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblMediaEntity SelectOne(int Id)
		{
			TblMediaEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblMediaEntity _TblMediaEntity = new TblMediaEntity(Id);
				if (adapter.FetchEntity(_TblMediaEntity))
				{
					toReturn = _TblMediaEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblMediaCollection = new EntityCollection( new TblMediaEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, null, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByCateMediaId(int CateMediaId)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.CateMediaId == CateMediaId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCateMediaIdRDT(int CateMediaId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.CateMediaId == CateMediaId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByCategoryName(string CategoryName)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.CategoryName == CategoryName);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCategoryNameRDT(string CategoryName)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.CategoryName == CategoryName);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByNhomFileId(int NhomFileId)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.NhomFileId == NhomFileId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByNhomFileIdRDT(int NhomFileId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.NhomFileId == NhomFileId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTenNhomFile(string TenNhomFile)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TenNhomFile == TenNhomFile);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTenNhomFileRDT(string TenNhomFile)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TenNhomFile == TenNhomFile);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByDinhDang(string DinhDang)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.DinhDang == DinhDang);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDinhDangRDT(string DinhDang)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.DinhDang == DinhDang);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTenMedia(string TenMedia)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TenMedia == TenMedia);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTenMediaRDT(string TenMedia)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TenMedia == TenMedia);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLink(string Link)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLinkRDT(string Link)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByDescription(string Description)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDescriptionRDT(string Description)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Description == Description);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByViTri(string ViTri)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.ViTri == ViTri);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByViTriRDT(string ViTri)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.ViTri == ViTri);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByThuTu(int ThuTu)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.ThuTu == ThuTu);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByThuTuRDT(int ThuTu)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.ThuTu == ThuTu);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByImage(string Image)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByImageRDT(string Image)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByType(string Type)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTypeRDT(string Type)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByNgayDang(DateTime NgayDang)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.NgayDang == NgayDang);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByNgayDangRDT(DateTime NgayDang)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.NgayDang == NgayDang);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLangId(string LangId)
		{
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblMediaCollection, filter, 0, null);
			}
			return _TblMediaCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLangIdRDT(string LangId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblMediaCollection = new EntityCollection(new TblMediaEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblMediaFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblMediaCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
